package com.neutech.maplestory.client.entity;

import com.neutech.maplestory.client.client.MapleStoryClint;
import com.neutech.maplestory.client.util.ImageUtil;

import java.awt.*;

/**
 * CLASS:Mob：
 * TODU:
 * date:2021/1/28、19:24
 * version:0.1
 */
public class Mob extends AbstractMapleStoryObject{
    public static Image[] images = new Image[100];
    static {
        for (int i = 0; i < 6; i++) {
            images[i] = ImageUtil.getImage("mob01_left_stand"+i);
        }
        for (int i = 6; i < 12; i++) {
            images[i] = ImageUtil.getImage("mob01_left_move"+(i-6));
        }
        for (int i = 12; i < 20; i++) {
            images[i] = ImageUtil.getImage("mob01_left_die"+(i-12));
        }
        images[20] = ImageUtil.getImage("blood");
    }
    public  int MAX_HP;
    public Mob(){
        this.live=true;
        this.speed =5;
        this.dir=Direction.LEFT;
        this.action = Action.STAND;
        this.width= images[0].getWidth(null);
        this.heigtht= images[0].getHeight(null);
        this.MAX_HP=100;
        this.HP = MAX_HP;
    }
    public Mob(MapleStoryClint msc,int x, int y,int speed){
        this();
        this.msc=msc;
        this.x=x;
        this.y=y;
        this.speed=speed;
    }
    /**
     * 一直加的计数器
     */
    public int count = 0;
    /**
     * 计算当前第几张图
     */
    private int step = 0;
    private int dieStep =0;
    @Override
    public void draw(Graphics g) {
        if(dieStep>=5){
            this.live=false;
            dieStep= 0;
        }
        if(!live){
            msc.mobs.remove(this);
            return;
        }
        switch (dir){
            case LEFT:
                switch (action){
                    case STAND:
                        if(count++ % 5 == 0){
                            g.drawImage(images[(step++ % 6)],x,y,null);
                        }else {
                            g.drawImage(images[step % 6], x, y, null);
                        }
                        break;
                    case WALK:
                        if(count++ % 5 == 0){
                            g.drawImage(images[(step++ % 6)+6],x,y,null);
                        }else {
                            g.drawImage(images[step % 6+6], x, y, null);
                        }
                        break;
                    case DIE:
                        if(count++ % 5 == 0){
                            g.drawImage(images[(dieStep++ % 8)+12],x,y,null);
                        }else {
                            g.drawImage(images[dieStep % 8+12], x, y, null);
                        }
                    default:
                        break;
                }
                break;
            case RIGHT:
                switch (action){
                    case STAND:
                        break;
                    default:
                        break;
                }
                break;
            default:
                break;
        }
        bloodBar.draw(g);
        move();

    }

    @Override
    public void move() {
       switch (dir){
           case LEFT:
               switch (action){
                   case WALK:
                       this.x-=speed;
                       break;
                   default:
                       break;
               }
               break;
           case RIGHT:
               this.x+=speed;
               break;
           default:
               break;
       }
    }
    public BloodBar bloodBar = new BloodBar();
    class BloodBar extends AbstractMapleStoryObject{
        private Image img;
        public BloodBar(){
            this.img = ImageUtil.getImage("blood");
            this.width = img.getWidth(null);
        }
        @Override
        public void draw(Graphics g) {
           /* Color c=g.getColor();
            //内部类访问外部类 相同属性名时，使用外部类.this.属性名
            g.drawRect(Mob.this.x,Mob.this.y-15,Mob.this.width,8);
            g.setColor(Color.green);
            g.fillRect(Mob.this.x+1,Mob.this.y-15+1,Mob.this.width*Mob.this.HP/Mob.this.MAX_HP-1,7);
            g.setColor(c);*/
            int n=Mob.this.width/this.width*Mob.this.HP/Mob.this.MAX_HP;
            for(int i=0;i<n;i++){
                g.drawImage(img,Mob.this.x+(i*this.width)+1,Mob.this.y-15,null);
            }

        }
    }
}
